home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / games_d / gnuchess.zip / UXDSP.C < prev    next >
Text File  |  1990-07-20  |  34KB  |  1,413 lines

  1. /* uxdsp.c - ALPHA interface for CHESS
  2.  
  3.   Revision: 1990-05-09
  4.  
  5.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  6.   Copyright (c) 1988, 1989, 1990  John Stanback
  7.  
  8.   This file is part of CHESS.
  9.  
  10.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  11.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  12.   the consequences of using it or for whether it serves any particular
  13.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  14.   General Public License for full details.
  15.  
  16.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  17.   only under the conditions described in the CHESS General Public License.
  18.   A copy of this license is supposed to have been given to you along with
  19.   CHESS so you can know your rights and responsibilities.  It should be in a
  20.   file named COPYING.  Among other things, the copyright notice and this
  21.   notice must be preserved on all copies.
  22. */
  23.  
  24. #include <ctype.h>
  25. #include <signal.h>
  26. #ifdef MSDOS
  27. #include <dos.h>
  28. #include <conio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <time.h>
  32.  
  33. #define ESC 0x1B
  34. #define scanz scanf
  35. #define printz printf
  36. #define refresh() fflush(stdout)
  37.  
  38. int mycntl1, mycntl2;
  39. static void param (short n);
  40. #else
  41. #include <sys/param.h>
  42. #include <sys/types.h>
  43. #include <sys/file.h>
  44. #include <curses.h>
  45.  
  46. #define scanz fflush(stdout),scanw
  47. #define printz printw
  48.  
  49. /* <stdlib.h> */
  50. extern void *malloc (size_t);
  51. extern void exit (int);
  52. /* <string.h> */
  53. extern char *strcat (char *, const char *);
  54. extern int strcmp (const char *, const char *);
  55. extern char *strcpy (char *, const char *);
  56. /* <time.h> */
  57. extern long int time (long int *);
  58. #endif /* MSDOS */
  59.  
  60. #include "gnuchess.h"
  61.  
  62. #define pxx " PNBRQK"
  63. #define qxx " pnbrqk"
  64. #define rxx "12345678"
  65. #define cxx "abcdefgh"
  66. #define TAB (46)
  67. #define VIR_C(s)  ((flag.reverse) ? 7-column(s) : column(s))
  68. #define VIR_R(s)  ((flag.reverse) ? 7-row(s) : row(s))
  69.  
  70. static char mvstr[4][6];
  71. static char* ColorStr[2] = {"White", "Black"};
  72. static long evrate;
  73.  
  74. #ifndef __ZTC__
  75. extern char *getenv (const char *);
  76. #endif
  77. void TerminateSearch (int), Die (int);
  78.  
  79. void
  80. Initialize (void)
  81. {
  82.   signal (SIGINT, Die);
  83. #ifndef MSDOS
  84.   signal (SIGQUIT, Die);
  85.   initscr ();
  86.   crmode ();
  87. #else
  88.   mycntl1 = mycntl2 = 0;
  89. #endif /* MSDOS */
  90. }
  91.  
  92. void
  93. ExitChess (void)
  94. {
  95.   ListGame ();
  96.   gotoXY (1, 24);
  97. #ifndef MSDOS
  98.   nocrmode ();
  99.   endwin ();
  100. #endif /* MSDOS */
  101.   exit (0);
  102. }
  103.  
  104. void
  105. Die (int Sig)
  106. {
  107.   char s[80];
  108.  
  109.   signal (SIGINT, SIG_IGN);
  110. #ifdef MSDOS
  111.   Sig++;                                /* shut up the compiler */
  112. #else
  113.   signal (SIGQUIT, SIG_IGN);
  114. #endif /* MSDOS */
  115.   ShowMessage ("Abort? ");
  116.   scanz ("%s", s);
  117.   if (strcmp (s, "yes") == 0)
  118.     ExitChess ();
  119.   signal (SIGINT, Die);
  120. #ifndef MSDOS
  121.   signal (SIGQUIT, Die);
  122. #endif /* MSDOS */
  123. }
  124.  
  125. void
  126. TerminateSearch (int Sig)
  127. {
  128.   signal (SIGINT, SIG_IGN);
  129. #ifdef MSDOS
  130.   Sig++;                                /* shut up the compiler */
  131. #else
  132.   signal (SIGQUIT, SIG_IGN);
  133. #endif /* MSDOS */
  134.   flag.timeout = true;
  135.   flag.bothsides = false;
  136.   signal (SIGINT, Die);
  137. #ifndef MSDOS
  138.   signal (SIGQUIT, Die);
  139. #endif /* MSDOS */
  140. }
  141.  
  142. void
  143. algbr (short int f, short int t, short int flag)
  144.  
  145. /*
  146.    Generate move strings in different formats.
  147. */
  148.  
  149. {
  150.   int m3p;
  151.  
  152.   if (f != t)
  153.     {
  154.       /* algebraic notation */
  155.       mvstr[0][0] = cxx[column (f)];
  156.       mvstr[0][1] = rxx[row (f)];
  157.       mvstr[0][2] = cxx[column (t)];
  158.       mvstr[0][3] = rxx[row (t)];
  159.       mvstr[0][4] = mvstr[3][0] = '\0';
  160.       if ((mvstr[1][0] = pxx[board[f]]) == 'P')
  161.         {
  162.           if (mvstr[0][0] == mvstr[0][2])       /* pawn did not eat */
  163.             {
  164.               mvstr[2][0] = mvstr[1][0] = mvstr[0][2];  /* to column */
  165.               mvstr[2][1] = mvstr[1][1] = mvstr[0][3];  /* to row */
  166.               m3p = 2;
  167.             }
  168.           else
  169.             /* pawn ate */
  170.             {
  171.               mvstr[2][0] = mvstr[1][0] = mvstr[0][0];  /* from column */
  172.               mvstr[2][1] = mvstr[1][1] = mvstr[0][2];  /* to column */
  173.               mvstr[2][2] = mvstr[0][3];
  174.               m3p = 3;          /* to row */
  175.             }
  176.           mvstr[2][m3p] = mvstr[1][2] = '\0';
  177.           if (flag & promote)
  178.             {
  179.               mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  180.               mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[0][5] = '\0';
  181.             }
  182.         }
  183.       else
  184.         /* not a pawn */
  185.         {
  186.           mvstr[2][0] = mvstr[1][0];
  187.           mvstr[2][1] = mvstr[0][1];
  188.           mvstr[2][2] = mvstr[1][1] = mvstr[0][2];      /* to column */
  189.           mvstr[2][3] = mvstr[1][2] = mvstr[0][3];      /* to row */
  190.           mvstr[2][4] = mvstr[1][3] = '\0';
  191.           strcpy (mvstr[3], mvstr[2]);
  192.           mvstr[3][1] = mvstr[0][0];
  193.           if (flag & cstlmask)
  194.             {
  195.               if (t > f)
  196.                 {
  197.                   strcpy (mvstr[1], "o-o");
  198.                   strcpy (mvstr[2], "O-O");
  199.                 }
  200.               else
  201.                 {
  202.                   strcpy (mvstr[1], "o-o-o");
  203.                   strcpy (mvstr[2], "O-O-O");
  204.                 }
  205.             }
  206.         }
  207.     }
  208.   else
  209.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  210. }
  211.  
  212. int
  213. VerifyMove (char *s, short int iop, unsigned short int *mv)
  214.  
  215. /*
  216.    Compare the string 's' to the list of legal moves available for the
  217.    opponent. If a match is found, make the move on the board.
  218. */
  219.  
  220. {
  221.   static short pnt, tempb, tempc, tempsf, tempst, cnt;
  222.   static struct leaf xnode;
  223.   struct leaf *node;
  224.  
  225.   *mv = 0;
  226.   if (iop == 2)
  227.     {
  228.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  229.       return (false);
  230.     }
  231.   cnt = 0;
  232.   MoveList (opponent, 2);
  233.   pnt = TrPnt[2];
  234.   while (pnt < TrPnt[3])
  235.     {
  236.       node = &Tree[pnt++];
  237.       algbr (node->f, node->t, (short) node->flags);
  238.       if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  239.           strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
  240.         {
  241.           cnt++;
  242.           xnode = *node;
  243.         }
  244.     }
  245.   if (cnt == 1)
  246.     {
  247.       MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  248.       if (SqAtakd (PieceList[opponent][0], computer))
  249.         {
  250.           UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  251.           ShowMessage ("Illegal Move!!");
  252.           return (false);
  253.         }
  254.       else
  255.         {
  256.           if (iop == 1)
  257.             return (true);
  258.           UpdateDisplay (xnode.f, xnode.t, 0, (short) xnode.flags);
  259.           if ((board[xnode.t] == pawn)
  260.               || (xnode.flags & capture)
  261.               || (xnode.flags & cstlmask))
  262.             {
  263.               Game50 = GameCnt;
  264.               ZeroRPT ();
  265.             }
  266.           GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  267.           GameList[GameCnt].nodes = 0;
  268.           ElapsedTime (1);
  269.           GameList[GameCnt].time = (short) et;
  270.           TimeControl.clock[opponent] -= et;
  271.           --TimeControl.moves[opponent];
  272.           *mv = (xnode.f << 8) | xnode.t;
  273.           algbr (xnode.f, xnode.t, false);
  274.           return (true);
  275.         }
  276.     }
  277.   if (cnt > 1)
  278.     ShowMessage ("Ambiguous Move!");
  279.   return (false);
  280. }
  281.  
  282. void
  283. help (void)
  284. {
  285.   ClrScreen ();
  286.   printz ("CHESS command summary\n");
  287.   printz ("g1f3     move from g1 to f3      quit      Exit Chess\n");
  288.   printz ("Nf3      move knight to f3       beep      on/off\n");
  289.   printz ("o-o      castle king side        easy      on/off\n");
  290.   printz ("o-o-o    castle queen side       hash      on/off\n");
  291.   printz ("bd       redraw board            reverse   board display\n");
  292.   printz ("list     game to chess.lst       book      on/off\n");
  293.   printz ("undo     undo last ply           remove    take back a move\n");
  294.   printz ("edit     edit board              force     enter game moves\n");
  295.   printz ("switch   sides with computer     both      computer match\n");
  296.   printz ("white    computer plays white    black     computer plays black\n");
  297.   printz ("depth    set search depth        level     select level\n");
  298.   printz ("post     principle variation     hint      suggest a move\n");
  299.   printz ("save     game to file            get       game from file\n");
  300.   printz ("random   randomize play          new       start new game\n");
  301.   printz ("rv       toggle reverse video    coords    toggle coords\n");
  302.   printz ("shade    toggle shade black      stars     toggle stars\n");
  303.   printz ("p        show coordinate values\n");
  304.   gotoXY (10, 21);
  305.   printz ("Computer: %s", ColorStr[computer]);
  306.   gotoXY (10, 22);
  307.   printz ("Opponent: %s", ColorStr[opponent]);
  308.   gotoXY (10, 23);
  309.   printz ("Level: %ld", Level);
  310.   gotoXY (10, 24);
  311.   printz ("Easy mode: %s", (flag.easy) ? "ON" : "OFF");
  312.   gotoXY (40, 21);
  313.   printz ("Depth: %d", MaxSearchDepth);
  314.   gotoXY (40, 22);
  315.   printz ("Random: %s", (dither) ? "ON" : "OFF");
  316.   gotoXY (40, 23);
  317.   printz ("Transposition table: %s", (flag.hash) ? "ON" : "OFF");
  318.   gotoXY (40, 24);
  319.   printz ("Hit <RET> to return: ");
  320.   refresh ();
  321.   fflush(stdin);
  322.   getchar();
  323.   ClrScreen ();
  324.   UpdateDisplay (0, 0, 1, 0);
  325. }
  326.  
  327. void
  328. EditBoard (void)
  329.  
  330. /*
  331.   Set up a board position. Pieces are entered by typing the piece
  332.   followed by the location. For example, Nf3 will place a knight on
  333.   square f3.
  334. */
  335.  
  336. {
  337.   short a, r, c, sq, i;
  338.   char s[80];
  339.  
  340.   ClrScreen ();
  341.   UpdateDisplay (0, 0, 1, 0);
  342.   gotoXY (TAB, 3);
  343.   printz (".   Exit to main");
  344.   gotoXY (TAB, 4);
  345.   printz ("#   Clear board");
  346.   gotoXY (TAB, 5);
  347.   printz ("c   Change sides");
  348.   gotoXY (TAB, 7);
  349.   printz ("Enter piece & location: ");
  350.   a = white;
  351.   do
  352.     {
  353.       gotoXY (TAB, 6);
  354.       printz ("Editing: %s", ColorStr[a]);
  355.       gotoXY (TAB + 24, 7);
  356.       ClrEoln ();
  357.       scanz ("%s", s);
  358.       if (s[0] == '#')
  359.         {
  360.           for(sq = 0; sq < 64; sq++)
  361.             {
  362.               board[sq] = no_piece;
  363.               color[sq] = neutral;
  364.               DrawPiece (sq);
  365.             }
  366.         }
  367.       if (s[0] == 'c' || s[0] == 'C')
  368.         a = otherside[a];
  369.       c = s[1] - 'a';
  370.       r = s[2] - '1';
  371.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  372.         {
  373.           sq = locn (r, c);
  374.           for (i = king; i > no_piece; i--)
  375.             if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  376.               break;
  377.           board[sq] = i;
  378.           color[sq] = (board[sq] == no_piece) ? neutral : a;
  379.           DrawPiece (sq);
  380.         }
  381.   } while (s[0] != '.');
  382.  
  383.   for (sq = 0; sq < 64; sq++)
  384.     Mvboard[sq] = (board[sq] != Stboard[sq]) ? 10 : 0;
  385.   GameCnt = 0;
  386.   Game50 = 1;
  387.   ZeroRPT ();
  388.   Sdepth = 0;
  389.   InitializeStats ();
  390.   ClrScreen ();
  391.   UpdateDisplay (0, 0, 1, 0);
  392. }
  393.  
  394. void
  395. ShowPlayers (void)
  396. {
  397.   gotoXY (5, ((flag.reverse) ? 23 : 2));
  398.   printz ("%s", (computer == black) ? "Computer" : "Human   ");
  399.   gotoXY (5, ((flag.reverse) ? 2 : 23));
  400.   printz ("%s", (computer == white) ? "Computer" : "Human   ");
  401. }
  402.  
  403. void
  404. ShowDepth (char ch)
  405. {
  406.   gotoXY (TAB, 4);
  407.   printz ("Depth= %d%c ", Sdepth, ch);
  408.   ClrEoln ();
  409. }
  410.  
  411. void
  412. ShowScore (short score)
  413. {
  414.   gotoXY (TAB, 5);
  415.   printz ("Score= %d", score);
  416.   ClrEoln ();
  417. }
  418.  
  419. void
  420. ShowMessage (char *s)
  421. {
  422.   gotoXY (TAB, 6);
  423.   printz ("%s", s);
  424.   ClrEoln ();
  425. }
  426.  
  427. void
  428. ClearMessage (void)
  429. {
  430.   gotoXY (TAB, 6);
  431.   ClrEoln ();
  432. }
  433.  
  434. void
  435. ShowCurrentMove (short int pnt, short int f, short int t)
  436. {
  437.   algbr (f, t, false);
  438.   gotoXY (TAB, 7);
  439.   printz ("(%2d) %4s", pnt, mvstr[0]);
  440. }
  441.  
  442. void
  443. ShowHeader (void)
  444. {
  445.   gotoXY (TAB, 2);
  446.   printz ("GNU Chess");
  447. }
  448.  
  449. void
  450. ShowSidetomove (void)
  451. {
  452.   gotoXY (TAB, 14);
  453.   printz ("%2d:   %s", 1 + GameCnt / 2, ColorStr[player]);
  454.   ClrEoln ();
  455. }
  456.  
  457. void
  458. ShowPrompt (void)
  459. {
  460.   gotoXY (TAB, 19);
  461.   printz ("Your move is? ");
  462.   ClrEoln ();
  463. }
  464.  
  465. void
  466. ShowNodeCnt (long int NodeCnt, long int evrate)
  467. {
  468.   gotoXY (TAB, 21);
  469.   printz ("Nodes= %8ld, Nodes/Sec= %5ld", NodeCnt, evrate);
  470.   ClrEoln ();
  471. }
  472.  
  473. void
  474. ShowResults (short int score, unsigned short int *bstline, char ch)
  475. {
  476.   unsigned char d, ply;
  477.   if (flag.post)
  478.     {
  479.       ShowDepth (ch);
  480.       ShowScore (score);
  481.       d = 7;
  482.       for (ply = 1; bstline[ply] > 0; ply++)
  483.         {
  484.           if (ply % 4 == 1)
  485.             {
  486.               gotoXY (TAB, ++d);
  487.               ClrEoln ();
  488.             }
  489.           algbr ((short) bstline[ply] >> 8, (short) bstline[ply] & 0xFF, false);
  490.           printz ("%5s ", mvstr[0]);
  491.         }
  492.       ClrEoln ();
  493.       while (d < 13)
  494.         {
  495.           gotoXY (TAB, ++d);
  496.           ClrEoln ();
  497.         }
  498.     }
  499. }
  500.  
  501. void
  502. SearchStartStuff (short int side)
  503. {
  504.   short i;
  505.  
  506.   signal (SIGINT, TerminateSearch);
  507. #ifdef MSDOS
  508.   side++;                               /* shut up the compiler */
  509. #else
  510.   signal (SIGQUIT, TerminateSearch);
  511. #endif /* MSDOS */
  512.   for (i = 4; i < 14; i++)
  513.     {
  514.       gotoXY (TAB, i);
  515.       ClrEoln ();
  516.     }
  517. }
  518.  
  519. void
  520. OutputMove (void)
  521. {
  522.   int i;
  523.  
  524.   UpdateDisplay (root->f, root->t, 0, (short) root->flags);
  525.   gotoXY (TAB, 17);
  526.   printz ("My move is: %s", mvstr[0]);
  527.   if (flag.beep)
  528.     putchar (7);
  529.   ClrEoln ();
  530.  
  531.   gotoXY (TAB, 24);
  532.   if (root->flags & draw)
  533.     printz ("Drawn game!");
  534.   else if (root->score == -9999)
  535.     printz ("Opponent mates!");
  536.   else if (root->score == 9998)
  537.     printz ("Computer mates!");
  538.   else if (root->score < -9000)
  539.     printz ("Opponent will soon mate!");
  540.   else if (root->score > 9000)
  541.     printz ("Computer will soon mate!");
  542.   ClrEoln ();
  543.  
  544.   if (flag.post)
  545.     {
  546.       ShowNodeCnt (NodeCnt, evrate);
  547.       gotoXY (TAB, 22);
  548.       for (i = 1999; i >= 0 && Tree[i].f == 0 && Tree[i].t == 0; i--) ;
  549.       printz ("Max Tree= %5d", i);
  550.       ClrEoln ();
  551.     }
  552. }
  553.  
  554. void
  555. ElapsedTime (short int iop)
  556.  
  557. /*
  558.   Determine the time that has passed since the search was started. If
  559.   the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
  560.   timeout to true which will terminate the search.
  561. */
  562.  
  563. {
  564.   et = time ((long *) 0) - time0;
  565.   if (et < 0)
  566.     et = 0;
  567.   ETnodes += 50;
  568.   if (et > et0 || iop == 1)
  569.     {
  570.       if (et > ResponseTime + ExtraTime && Sdepth > 1)
  571.         flag.timeout = true;
  572.       et0 = et;
  573.       if (iop == 1)
  574.         {
  575.           time0 = time ((long *) 0);
  576.           et0 = 0;
  577.         }
  578.       if (et > 0)
  579.         /* evrate used to be Nodes / cputime I dont` know why */
  580.         evrate = NodeCnt / (et + ft);
  581.       else
  582.         evrate = 0;
  583.       ETnodes = NodeCnt + 50;
  584.       UpdateClocks ();
  585.     }
  586. }
  587.  
  588. void
  589. UpdateClocks (void)
  590. {
  591.   short m, s;
  592.   m = (short) (et / 60);
  593.   s = (short) (et - 60 * (long) m);
  594.   if (TCflag)
  595.     {
  596.       m = (short) ((TimeControl.clock[player] - et) / 60);
  597.       s = (short) (TimeControl.clock[player] - et - 60 * (long) m);
  598.     }
  599.   if (m < 0)
  600.     m = 0;
  601.   if (s < 0)
  602.     s = 0;
  603.   if (player == white)
  604.     gotoXY (20, (flag.reverse) ? 2 : 23);
  605.   else
  606.     gotoXY (20, (flag.reverse) ? 23 : 2);
  607.   printz ("%d:%2d   ", m, s);
  608.   if (flag.post)
  609.     ShowNodeCnt (NodeCnt, evrate);
  610.   refresh ();
  611. }
  612.  
  613. void
  614. SetTimeControl (void)
  615. {
  616.   if (TCflag)
  617.     {
  618.       TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
  619.       TimeControl.clock[white] = TimeControl.clock[black] = 60 * (long) TCminutes;
  620.     }
  621.   else
  622.     {
  623.       TimeControl.moves[white] = TimeControl.moves[black] = 0;
  624.       TimeControl.clock[white] = TimeControl.clock[black] = 0;
  625.       Level = 60 * (long) TCminutes;
  626.     }
  627.   et = 0;
  628.   ElapsedTime (1);
  629. }
  630.  
  631. void
  632. gotoXY (short int x, short int y)
  633. {
  634. #ifdef MSDOS
  635.   putchar(ESC);
  636.   putchar('[');
  637.   param(y);
  638.   putchar(';');
  639.   param(x);
  640.   putchar('H');
  641. #else
  642.   move (y - 1, x - 1);
  643. #endif /* MSDOS */
  644. }
  645.  
  646. void
  647. ClrScreen (void)
  648. {
  649. #ifdef MSDOS
  650.   putchar(ESC);
  651.   putchar('[');
  652.   putchar('2');
  653.   putchar('J');
  654. #else
  655.   clear ();
  656. #endif /* MSDOS */
  657.   refresh ();
  658. }
  659.  
  660. void
  661. ClrEoln (void)
  662. {
  663. #ifdef MSDOS
  664.   putchar(ESC);
  665.   putchar('[');
  666.   putchar('K');
  667. #else
  668.   clrtoeol ();
  669. #endif /* MSDOS */
  670.   refresh ();
  671. }
  672.  
  673. #ifdef MSDOS
  674. void
  675. param(short n)
  676. {
  677.   if (n >= 10)
  678.     {
  679.     register short d, q;
  680.     q = n/10; d = n%10;
  681.     putchar(q + '0');
  682.     putchar(d + '0');
  683.   }
  684.   else
  685.     putchar(n + '0');
  686. }
  687. #endif /* MSDOS */
  688.  
  689. void
  690. DrawPiece (short int sq)
  691. {
  692.   register char x;
  693.  
  694.   if (color[sq] == black)
  695. #if defined(MSDOS) && !defined(SEVENBIT)
  696.     x = '7';                            /* print WHITE boldface, */
  697.   else
  698.     x = '1';                            /* print BLACK inverted  */
  699.   gotoXY (6 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq)));
  700.   printz ("\033[%cm%c\033[0m", x, pxx[board[sq]]);
  701. #else
  702.     x = '*';
  703.   else
  704.     x = ' ';
  705.   gotoXY (5 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq)));
  706.   printz ("%c%c ", x, pxx[board[sq]]);
  707. #endif /* MSDOS && !SEVENBIT */
  708. }
  709.  
  710. void
  711. ShowPostnValue (short int sq)
  712.  
  713. /*
  714.   must have called ExaminePosition() first
  715. */
  716.  
  717. {
  718.   short score;
  719.  
  720.   gotoXY (4 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq)));
  721.   ScorePosition(color[sq], &score);
  722.   if (color[sq] != neutral)
  723.     printz ("%3d ", svalue[sq]);
  724.   else
  725.     printz ("   ");
  726. }
  727.  
  728. void
  729. ShowPostnValues (void)
  730. {
  731.   short sq, score;
  732.  
  733.   ExaminePosition ();
  734.   for (sq = 0; sq < 64; sq++)
  735.     ShowPostnValue (sq);
  736.   ScorePosition (opponent, &score);
  737.   ShowScore (score);
  738. }
  739.  
  740. void
  741. UpdateDisplay (short int f, short int t, short int redraw, short int isspec)
  742. {
  743.   short i, sq, z;
  744.  
  745.   if (redraw)
  746.     {
  747.       ShowHeader ();
  748.       ShowPlayers ();
  749.  
  750.       i = 3;
  751.       gotoXY (3, ++i);
  752. #if defined(MSDOS) && !defined(SEVENBIT)
  753.       printz ("\332\304\304\304\304\302\304\304\304\304\302\304\304\304\304"\
  754.               "\302\304\304\304\304\302\304\304\304\304\302\304\304\304\304"\
  755.               "\302\304\304\304\304\302\304\304\304\304\277");
  756. #else
  757.       printz ("+----+----+----+----+----+----+----+----+");
  758. #endif /* MSDOS && !SEVENBIT */
  759.       while (i < 19)
  760.         {
  761.           gotoXY (1, ++i);
  762.           if (flag.reverse)
  763.             z = (i / 2) - 1;
  764.           else
  765.             z = 10 - (i / 2);
  766. #if defined(MSDOS) && !defined(SEVENBIT)
  767.           printz ("%d \263    \263    \263    \263    \263    \263    "\
  768.                   "\263    \263    \263",z);
  769. #else
  770.           printz ("%d |    |    |    |    |    |    |    |    |",z);
  771. #endif /* MSDOS && !SEVENBIT */
  772.           gotoXY (3, ++i);
  773.           if (i < 19)
  774. #if defined(MSDOS) && !defined(SEVENBIT)
  775.             printz ("\303\304\304\304\304\305\304\304\304\304\305\304\304"\
  776.                     "\304\304\305\304\304\304\304\305\304\304\304\304\305"\
  777.                     "\304\304\304\304\305\304\304\304\304\305\304\304\304"\
  778.                     "\304\264");
  779. #else
  780.             printz ("+----+----+----+----+----+----+----+----+");
  781. #endif /* MSDOS && !SEVENBIT */
  782.         }
  783. #if defined(MSDOS) && !defined(SEVENBIT)
  784.       printz ("\300\304\304\304\304\301\304\304\304\304\301\304\304\304\304"\
  785.               "\301\304\304\304\304\301\304\304\304\304\301\304\304\304\304"\
  786.               "\301\304\304\304\304\301\304\304\304\304\331");
  787. #else
  788.       printz ("+----+----+----+----+----+----+----+----+");
  789. #endif /* MSDOS && !SEVENBIT */
  790.       gotoXY (3, 21);
  791.       if (flag.reverse)
  792.         printz ("  h    g    f    e    d    c    b    a");
  793.       else
  794.         printz ("  a    b    c    d    e    f    g    h");
  795.       for (sq = 0; sq < 64; sq++)
  796.         DrawPiece (sq);
  797.     }
  798.   else
  799.     {
  800.       DrawPiece (f);
  801.       DrawPiece (t);
  802.       if (isspec & cstlmask)
  803.         if (t > f)
  804.           {
  805.             DrawPiece (f + 3);
  806.             DrawPiece (t - 1);
  807.           }
  808.         else
  809.           {
  810.             DrawPiece (f - 4);
  811.             DrawPiece (t + 1);
  812.           }
  813.       else if (isspec & epmask)
  814.         {
  815.           DrawPiece (t - 8);
  816.           DrawPiece (t + 8);
  817.         }
  818.     }
  819.   refresh ();
  820. }
  821.  
  822. void
  823. GetGame (void)
  824. {
  825.   FILE *fd;
  826.   char fname[256], tname[256];
  827.   char *tmp;
  828.   int c;
  829.   short sq;
  830.   unsigned short m;
  831.  
  832.   tname[0] = 0;
  833.  
  834.   if ((tmp = getenv ("HOME")) != 0)
  835.     strcpy (fname, tmp);
  836.   else
  837.     fname[0] = '\0';
  838.   strcat (fname, "/");
  839.  
  840.   ShowMessage ("File name: ");
  841.   scanz ("%s", tname);
  842.  
  843.   if (tname[0])
  844.     strcat (fname, tname);
  845.   else
  846.     strcat (fname, "chess.000");
  847.  
  848.   ShowMessage("Loading ");
  849.   printz ("%s", fname);
  850.  
  851.   if ((fd = fopen (fname, "r")) == NULL)
  852.     {
  853.       ShowMessage ("Load failed");
  854.       return;
  855.     }
  856.  
  857.   fscanf (fd, "%hd%hd%hd", &computer, &opponent, &Game50);
  858.   fscanf (fd, "%hd%hd", &castld[white], &castld[black]);
  859.   fscanf (fd, "%hd%hd", &TCflag, &OperatorTime);
  860.   fscanf (fd, "%ld%ld%hd%hd",
  861.           &TimeControl.clock[white], &TimeControl.clock[black],
  862.           &TimeControl.moves[white], &TimeControl.moves[black]);
  863.   for (sq = 0; sq < 64; sq++)
  864.     {
  865.       fscanf (fd, "%hd%hd", &m, &Mvboard[sq]);
  866.       board[sq] = (m >> 8);
  867.       color[sq] = (m & 0xFF);
  868.       if (color[sq] == 0)
  869.         color[sq] = neutral;
  870.       else
  871.         --color[sq];
  872.     }
  873.   GameCnt = 0;
  874.   c = '?';
  875.   while (c != EOF)
  876.     {
  877.       ++GameCnt;
  878.       c = fscanf (fd, "%hd%hd%hd%ld%hd%hd%hd", &GameList[GameCnt].gmove,
  879.                   &GameList[GameCnt].score, &GameList[GameCnt].depth,
  880.                   &GameList[GameCnt].nodes, &GameList[GameCnt].time,
  881.                   &GameList[GameCnt].piece, &GameList[GameCnt].color);
  882.       if (GameList[GameCnt].color == 0)
  883.         GameList[GameCnt].color = neutral;
  884.       else
  885.         --GameList[GameCnt].color;
  886.     }
  887.   GameCnt--;
  888.   if (TimeControl.clock[white] > 0)
  889.     TCflag = true;
  890.   computer--;
  891.   opponent--;
  892.  
  893.   fclose (fd);
  894.  
  895.   InitializeStats ();
  896.   Sdepth = 0;
  897.   ShowMessage ("Load done.  Press <Ret>");
  898.   fflush (stdin);
  899.   getchar ();
  900.   UpdateDisplay (0, 0, 1, 0);
  901.  
  902. }
  903.  
  904. void
  905. SaveGame (void)
  906. {
  907.   FILE *fd;
  908.   char fname[256], tname[256];
  909.   char *tmp;
  910.   short sq, i, c;
  911.  
  912.   tname[0] = 0;
  913.  
  914.   if ((tmp = getenv ("HOME")) != 0)
  915.     strcpy (fname, tmp);
  916.   else
  917.     fname[0] = '\0';
  918.   strcat (fname, "/");
  919.  
  920.   ShowMessage ("File name: ");
  921.   refresh ();
  922.   scanz ("%s", tname);
  923.  
  924.   if (tname[0])
  925.     strcat (fname, tname);
  926.   else
  927.     strcat (fname, "chess.000");
  928.  
  929.   ShowMessage("Saving ");
  930.   printz ("%s", fname);
  931.  
  932.   if (NULL == (fd = fopen (fname, "w")))
  933.     {
  934.       ShowMessage ("Not saved");
  935.       return;
  936.     }
  937.  
  938.   fprintf (fd, "%d %d %d\n", computer + 1, opponent + 1, Game50);
  939.   fprintf (fd, "%d %d\n", castld[white], castld[black]);
  940.   fprintf (fd, "%d %d\n", TCflag, OperatorTime);
  941.   fprintf (fd, "%ld %ld %d %d\n",
  942.            TimeControl.clock[white], TimeControl.clock[black],
  943.            TimeControl.moves[white], TimeControl.moves[black]);
  944.   for (sq = 0; sq < 64; sq++)
  945.     {
  946.       if (color[sq] == neutral)
  947.         c = 0;
  948.       else
  949.         c = color[sq] + 1;
  950.       fprintf (fd, "%d %d\n", 256 * board[sq] + c, Mvboard[sq]);
  951.     }
  952.   for (i = 1; i <= GameCnt; i++)
  953.     {
  954.       if (GameList[i].color == neutral)
  955.         c = 0;
  956.       else
  957.         c = GameList[i].color + 1;
  958.       fprintf (fd, "%d %d %d %ld %d %d %d\n",
  959.                GameList[i].gmove, GameList[i].score, GameList[i].depth,
  960.                GameList[i].nodes, GameList[i].time,
  961.                GameList[i].piece, c);
  962.     }
  963.   fclose (fd);
  964.   ShowMessage ("Save done.  Press <Ret>");
  965.   fflush (stdin);
  966.   getchar ();
  967. }
  968.  
  969. void
  970. ListGame (void)
  971. {
  972.   FILE *fd;
  973.   char fname[256];
  974.   char *tmp;
  975.   short i, f, t;
  976.  
  977.   if ((tmp = getenv ("HOME")) != 0)
  978.     strcpy (fname, tmp);
  979.   else
  980.     fname[0] = '\0';
  981.   strcat (fname, "/chess.lst");
  982.  
  983.   if ((fd = fopen (fname, "w")) != 0)
  984.     ShowMessage ("Writing ~/chess.lst");
  985.   else
  986.     {
  987.       ShowMessage ("Cannot write ~/chess.lst");
  988.       return;
  989.     }
  990.  
  991.   fprintf (fd, "\n");
  992.   fprintf (fd, "       score  depth   nodes  time         ");
  993.   fprintf (fd, "       score  depth   nodes  time\n");
  994.   for (i = 1; i <= GameCnt; i++)
  995.     {
  996.       f = GameList[i].gmove >> 8;
  997.       t = (GameList[i].gmove & 0xFF);
  998.       algbr (f, t, false);
  999.       if ((i % 2) == 0)
  1000.         fprintf (fd, "\n");
  1001.       else
  1002.         fprintf (fd, "         ");
  1003.       fprintf (fd, "%5s  %5d     %2d %7ld %5d", mvstr[0],
  1004.                GameList[i].score, GameList[i].depth,
  1005.                GameList[i].nodes, GameList[i].time);
  1006.     }
  1007.   fprintf (fd, "\n\n");
  1008.   fclose (fd);
  1009.   ShowMessage ("~/chess.lst written");
  1010. }
  1011.  
  1012. void
  1013. Undo (void)
  1014.  
  1015. /*
  1016.   Undo the most recent half-move.
  1017. */
  1018.  
  1019. {
  1020.   short f, t;
  1021.   f = GameList[GameCnt].gmove >> 8;
  1022.   t = GameList[GameCnt].gmove & 0xFF;
  1023.   if (board[t] == king && distance (t, f) > 1)
  1024.     (void) castle (GameList[GameCnt].color, f, t, 2);
  1025.   else
  1026.     {
  1027.       /* Check for promotion: */
  1028.       if ((color[t] == white && row (f) == 6 && row (t) == 7)
  1029.           || (color[t] == black && row (f) == 1 && row (t) == 0))
  1030.         {
  1031.           int g, from = f;
  1032.           for (g = GameCnt - 1; g > 0; g--)
  1033.             if (GameList[g].gmove & 0xFF == from)
  1034.               from = GameList[g].gmove >> 8;
  1035.           if ((color[t] == white && row (from) == 1)
  1036.               || (color[t] == black && row (from) == 6))
  1037.             board[t] = pawn;
  1038.         }
  1039.       board[f] = board[t];
  1040.       color[f] = color[t];
  1041.       board[t] = GameList[GameCnt].piece;
  1042.       color[t] = GameList[GameCnt].color;
  1043.       if (color[t] != neutral)
  1044.         Mvboard[t]--;
  1045.       Mvboard[f]--;
  1046.     }
  1047.   if (TCflag)
  1048.     ++TimeControl.moves[color[f]];
  1049.   GameCnt--;
  1050.   computer = otherside[computer];
  1051.   opponent = otherside[opponent];
  1052.   flag.mate = false;
  1053.   Sdepth = 0;
  1054.   UpdateDisplay (0, 0, 1, 0);
  1055.   InitializeStats ();
  1056. }
  1057.  
  1058. void
  1059. ChangeAlphaWindow (void)
  1060. {
  1061.   ShowMessage ("Awindow= ");
  1062.   scanz ("%hd", &Awindow);
  1063. }
  1064.  
  1065. void
  1066. ChangeBetaWindow (void)
  1067. {
  1068.   ShowMessage ("Bwindow= ");
  1069.   scanz ("%hd", &Bwindow);
  1070. }
  1071.  
  1072. void
  1073. GiveHint (void)
  1074. {
  1075.   char s[40];
  1076.   algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
  1077.   strcpy (s, "try ");
  1078.   strcat (s, mvstr[0]);
  1079.   ShowMessage (s);
  1080. }
  1081.  
  1082. void
  1083. ChangeSearchDepth (void)
  1084. {
  1085.   ShowMessage ("depth= ");
  1086.   scanz ("%hd", &MaxSearchDepth);
  1087. }
  1088.  
  1089. void
  1090. SetContempt (void)
  1091. {
  1092.   ShowMessage ("contempt= ");
  1093.   scanz ("%hd", &contempt);
  1094. }
  1095.  
  1096. void
  1097. ChangeXwindow (void)
  1098. {
  1099.   ShowMessage ("xwndw= ");
  1100.   scanz ("%hd", &xwndw);
  1101. }
  1102.  
  1103. void
  1104. SelectLevel (void)
  1105. {
  1106.   ClrScreen ();
  1107.   gotoXY (32, 2);
  1108.   printz ("CHESS");
  1109.   gotoXY (20, 4);
  1110.   printz (" 1.   60 moves in   5 minutes");
  1111.   gotoXY (20, 5);
  1112.   printz (" 2.   60 moves in  15 minutes");
  1113.   gotoXY (20, 6);
  1114.   printz (" 3.   60 moves in  30 minutes");
  1115.   gotoXY (20, 7);
  1116.   printz (" 4.   40 moves in  30 minutes");
  1117.   gotoXY (20, 8);
  1118.   printz (" 5.   40 moves in  60 minutes");
  1119.   gotoXY (20, 9);
  1120.   printz (" 6.   40 moves in 120 minutes");
  1121.   gotoXY (20, 10);
  1122.   printz (" 7.   40 moves in 240 minutes");
  1123.   gotoXY (20, 11);
  1124.   printz (" 8.    1 move  in  15 minutes");
  1125.   gotoXY (20, 12);
  1126.   printz (" 9.    1 move  in  60 minutes");
  1127.   gotoXY (20, 13);
  1128.   printz ("10.    1 move  in 600 minutes");
  1129.  
  1130.   OperatorTime = 1;
  1131.   TCmoves = 60;
  1132.   TCminutes = 5;
  1133.  
  1134.   gotoXY (20, 17);
  1135.   printz ("Enter Level: ");
  1136.   refresh ();
  1137.   scanz ("%ld", &Level);
  1138.   switch ((int) Level)
  1139.     {
  1140.     case 1:
  1141.       TCmoves = 60;
  1142.       TCminutes = 5;
  1143.       break;
  1144.     case 2:
  1145.       TCmoves = 60;
  1146.       TCminutes = 15;
  1147.       break;
  1148.     case 3:
  1149.       TCmoves = 60;
  1150.       TCminutes = 30;
  1151.       break;
  1152.     case 4:
  1153.       TCmoves = 40;
  1154.       TCminutes = 30;
  1155.       break;
  1156.     case 5:
  1157.       TCmoves = 40;
  1158.       TCminutes = 60;
  1159.       break;
  1160.     case 6:
  1161.       TCmoves = 40;
  1162.       TCminutes = 120;
  1163.       break;
  1164.     case 7:
  1165.       TCmoves = 40;
  1166.       TCminutes = 240;
  1167.       break;
  1168.     case 8:
  1169.       TCmoves = 1;
  1170.       TCminutes = 15;
  1171.       break;
  1172.     case 9:
  1173.       TCmoves = 1;
  1174.       TCminutes = 60;
  1175.       break;
  1176.     case 10:
  1177.       TCmoves = 1;
  1178.       TCminutes = 600;
  1179.       break;
  1180.     }
  1181.  
  1182.   TCflag = (TCmoves > 1);
  1183.   SetTimeControl ();
  1184.   ClrScreen ();
  1185.   UpdateDisplay (0, 0, 1, 0);
  1186. }
  1187.  
  1188. void
  1189. DoDebug (void)
  1190. {
  1191.   short c, p, sq, tp, tc, tsq, score;
  1192.   char s[40];
  1193.  
  1194.   ExaminePosition ();
  1195.   ShowMessage ("Enter piece: ");
  1196.   scanz ("%s", s);
  1197.   c = neutral;
  1198.   if (s[0] == 'w' || s[0] == 'W')
  1199.     c = white;
  1200.   if (s[0] == 'b' || s[0] == 'B')
  1201.     c = black;
  1202.   for(p = king; p > no_piece; p--)
  1203.     if ((s[1] == pxx[p]) || (s[1] == qxx[p]))
  1204.       break;
  1205.   for (sq = 0; sq < 64; sq++)
  1206.     {
  1207.       tp = board[sq];
  1208.       tc = color[sq];
  1209.       board[sq] = p;
  1210.       color[sq] = c;
  1211.       tsq = PieceList[c][1];
  1212.       PieceList[c][1] = sq;
  1213.       ShowPostnValue (sq);
  1214.       PieceList[c][1] = tsq;
  1215.       board[sq] = tp;
  1216.       color[sq] = tc;
  1217.     }
  1218.   ScorePosition (opponent, &score);
  1219.   ShowScore (score);
  1220. }
  1221.  
  1222. void
  1223. TestSpeed(void (*f) (short int side, short int ply))
  1224. {
  1225.   short i;
  1226.   long t1, t2;
  1227.  
  1228.   t1 = time (0);
  1229.   for (i = 0; i < 10000; i++)
  1230.     {
  1231.       f (opponent, 2);
  1232.     }
  1233.   t2 = time (0);
  1234.   NodeCnt = 10000L * (TrPnt[3] - TrPnt[2]);
  1235.   evrate = NodeCnt / (t2 - t1);
  1236.   ShowNodeCnt (NodeCnt, evrate);
  1237. }
  1238.  
  1239. void
  1240. InputCommand (void)
  1241.  
  1242. /*
  1243.   Process the users command. If easy mode is OFF (the computer is thinking
  1244.   on opponents time) and the program is out of book, then make the 'hint'
  1245.   move on the board and call SelectMove() to find a response. The user
  1246.   terminates the search by entering ^C (quit siqnal) before entering a
  1247.   command. If the opponent does not make the hint move, then set Sdepth to
  1248.   zero.
  1249. */
  1250.  
  1251. {
  1252.   short ok, tmp;
  1253.   unsigned short mv;
  1254.   char s[80];
  1255.  
  1256.   ok = flag.quit = false;
  1257.   player = opponent;
  1258.   ShowSidetomove ();
  1259.   ft = 0;
  1260.   if (hint > 0 && !flag.easy && Book == NULL)
  1261.     {
  1262.       fflush (stdout);
  1263.       time0 = time ((long *) 0);
  1264.       algbr ((short) hint >> 8, (short) hint & 0xFF, false);
  1265.       strcpy (s, mvstr[0]);
  1266.       tmp = epsquare;
  1267.       if (VerifyMove (s, 1, &mv))
  1268.         {
  1269.           ShowPrompt ();
  1270.           SelectMove (computer, 2);
  1271.           (void) VerifyMove (mvstr[0], 2, &mv);
  1272.           if (Sdepth > 0)
  1273.             Sdepth--;
  1274.         }
  1275.       ft = time ((long *) 0) - time0;
  1276.       epsquare = tmp;
  1277.     }
  1278.   signal (SIGINT, Die);
  1279. #ifndef MSDOS
  1280.   signal (SIGQUIT, Die);
  1281. #endif /* MSDOS */
  1282.   while (!(ok || flag.quit))
  1283.     {
  1284.       ShowPrompt ();
  1285.       scanz ("%s", s);
  1286.       player = opponent;
  1287.       ok = VerifyMove (s, 0, &mv);
  1288.       if (ok && mv != hint)
  1289.         {
  1290.           Sdepth = 0;
  1291.           ft = 0;
  1292.         }
  1293.       if (*s == '\0')
  1294.         UpdateDisplay (0, 0, 1, 0);
  1295.       if (strcmp (s, "bd") == 0)
  1296.         {
  1297.           ClrScreen ();
  1298.           UpdateDisplay (0, 0, 1, 0);
  1299.         }
  1300.       if ((strcmp (s, "quit") == 0) || (strcmp (s, "exit") == 0))
  1301.         flag.quit = true;
  1302.       if (strcmp (s, "post") == 0)
  1303.         flag.post = !flag.post;
  1304.       if (strcmp (s, "edit") == 0)
  1305.         EditBoard ();
  1306.       if (strcmp (s, "go") == 0)
  1307.         ok = true;
  1308.       if (strcmp (s, "help") == 0)
  1309.         help ();
  1310.       if (strcmp (s, "force") == 0)
  1311.         flag.force = !flag.force;
  1312.       if (strcmp (s, "book") == 0)
  1313.         Book = NULL;
  1314.       if (strcmp (s, "undo") == 0 && GameCnt > 0)
  1315.         Undo ();
  1316.       if (strcmp (s, "new") == 0)
  1317.         NewGame ();
  1318.       if (strcmp (s, "list") == 0)
  1319.         ListGame ();
  1320.       if (strcmp (s, "level") == 0)
  1321.         SelectLevel ();
  1322.       if (strcmp (s, "hash") == 0)
  1323.         flag.hash = !flag.hash;
  1324.       if (strcmp (s, "beep") == 0)
  1325.         flag.beep = !flag.beep;
  1326.       if (strcmp (s, "Awindow") == 0)
  1327.         ChangeAlphaWindow ();
  1328.       if (strcmp (s, "Bwindow") == 0)
  1329.         ChangeBetaWindow ();
  1330.       if (strcmp (s, "hint") == 0)
  1331.         GiveHint ();
  1332.       if (strcmp (s, "both") == 0)
  1333.         {
  1334.           flag.bothsides = !flag.bothsides;
  1335.           Sdepth = 0;
  1336.           SelectMove (opponent, 1);
  1337.           ok = true;
  1338.         }
  1339.       if (strcmp (s, "reverse") == 0)
  1340.         {
  1341.           flag.reverse = !flag.reverse;
  1342.           ClrScreen ();
  1343.           UpdateDisplay (0, 0, 1, 0);
  1344.         }
  1345.       if (strcmp (s, "switch") == 0)
  1346.         {
  1347.           computer = otherside[computer];
  1348.           opponent = otherside[opponent];
  1349.           flag.force = false;
  1350.           Sdepth = 0;
  1351.           ok = true;
  1352.         }
  1353.       if (strcmp (s, "white") == 0)
  1354.         {
  1355.           computer = white;
  1356.           opponent = black;
  1357.           ok = true;
  1358.           flag.force = false;
  1359.           Sdepth = 0;
  1360.         }
  1361.       if (strcmp (s, "black") == 0)
  1362.         {
  1363.           computer = black;
  1364.           opponent = white;
  1365.           ok = true;
  1366.           flag.force = false;
  1367.           Sdepth = 0;
  1368.         }
  1369.       if (strcmp (s, "remove") == 0 && GameCnt > 1)
  1370.         {
  1371.           Undo ();
  1372.           Undo ();
  1373.         }
  1374.       if (strcmp (s, "get") == 0)
  1375.         GetGame ();
  1376.       if (strcmp (s, "save") == 0)
  1377.         SaveGame ();
  1378.       if (strcmp (s, "depth") == 0)
  1379.         ChangeSearchDepth ();
  1380.       if (strcmp (s, "random") == 0)
  1381.         dither = 6;
  1382.       if (strcmp (s, "easy") == 0)
  1383.         flag.easy = !flag.easy;
  1384.       if (strcmp (s, "contempt") == 0)
  1385.         SetContempt ();
  1386.       if (strcmp (s, "xwndw") == 0)
  1387.         ChangeXwindow ();
  1388.       if (strcmp (s, "test") == 0)
  1389.         {
  1390.           ShowMessage("Testing MoveList Speed");
  1391.           TestSpeed (MoveList);
  1392.           ShowMessage("Testing CaptureList Speed");
  1393.           TestSpeed (CaptureList);
  1394.         }
  1395.       if (strcmp (s, "p") == 0)
  1396.         ShowPostnValues ();
  1397.       if (strcmp (s, "debug") == 0)
  1398.         DoDebug ();
  1399.     }
  1400.  
  1401.   ClearMessage ();
  1402.   ElapsedTime (1);
  1403.   if (flag.force)
  1404.     {
  1405.       computer = opponent;
  1406.       opponent = otherside[computer];
  1407.     }
  1408.   signal (SIGINT, TerminateSearch);
  1409. #ifndef MSDOS
  1410.   signal (SIGQUIT, TerminateSearch);
  1411. #endif /* MSDOS */
  1412. }
  1413.